package cn.lcj.user.controller;

import cn.lcj.basic.dto.PhoneCodeDto;
import cn.lcj.basic.utils.AjaxResult;
import cn.lcj.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * $
 *
 * @return $
 * @date $ $
 * @description $
 */
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String key){
        try {
            String base64str=verifyCodeService.getImageCode(key);
            return AjaxResult.me().setObj(base64str);
        } catch (RuntimeException e) {
            return new AjaxResult(false,e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后再试");
        }

    }
    @PostMapping("/phone")
    public AjaxResult getPhoneCode(@RequestBody PhoneCodeDto dto){
        try {
            verifyCodeService.getPhoneCode(dto);
            return AjaxResult.me();
        } catch (RuntimeException e) {
            return new AjaxResult(false,e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后再试");
        }

    }
    @PostMapping("/binderSmsCode")
    public AjaxResult getBinderSmsCodeCode(@RequestBody PhoneCodeDto dto){
        try {
            verifyCodeService.getBinderSmsCodeCode(dto);
            return AjaxResult.me();
        } catch (RuntimeException e) {
            return new AjaxResult(false,e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后再试");
        }

    }
}
